Skip to content

fix(hrp): symmetrise correlation distance before squareform (2.0.1)#13

Merged
hamid-arian merged 1 commit into
mainfrom
fix/hrp-asymmetric-distance
Jun 20, 2026
Merged

fix(hrp): symmetrise correlation distance before squareform (2.0.1)#13
hamid-arian merged 1 commit into
mainfrom
fix/hrp-asymmetric-distance

Conversation

@hamid-arian

Copy link
Copy Markdown
Member

Problem

optimization.hrp.hrp raised ValueError: Distance matrix 'X' must be symmetric whenever the input correlation matrix was only symmetric to floating-point tolerance. That is the normal case for correlation matrices produced by cov_to_corr or denoise_cov, where sub-epsilon asymmetry (~1e-16) is unavoidable. The failure surfaced while building the Python portfolio-construction tutorial (parity with Notebooks.jl).

Fix

Symmetrise the correlation distance ((d + dᵀ)/2, zero diagonal) before scipy.spatial.distance.squareform. Clustering output is unchanged for genuinely symmetric input. This mirrors the same fix already shipped in RiskLabAI.jl v0.5.1 ((distance .+ distance') ./ 2).

Tests

  • New regression test test_hrp_asymmetric_correlation (fails on main, passes here).
  • Full test/optimization/ suite green (12 passed).

Patch version bump 2.0.0 → 2.0.1; CHANGELOG updated.

🤖 Generated with Claude Code

hrp() raised "ValueError: Distance matrix must be symmetric" when the
correlation matrix was only symmetric to floating-point tolerance — the
normal case for matrices coming from cov_to_corr or denoise_cov, where
sub-epsilon asymmetry is unavoidable. Average the distance with its
transpose and zero the diagonal before squareform; clustering is
unchanged. Mirrors the same fix in RiskLabAI.jl v0.5.1.

Adds a regression test (test_hrp_asymmetric_correlation) and bumps the
patch version to 2.0.1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hamid-arian hamid-arian merged commit 9c4fc68 into main Jun 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant